var request = require('request');
var getWbaccesstoken = require('../src/getWbaccesstoken');
var config = require('../appConfig').sinaconfig;
var infoUrl = config.wbInfoUrl;

var getWbInfo = function(code) {
    return new Promise(function (resolve, reject) {
        getWbaccesstoken(code).then(function (data) {
               var data = JSON.parse(data);
               var url = infoUrl+'?access_token='+data.access_token +'&uid='+data.uid;
               request.get(url, (err, res, body) => {
                   if (err) {
                       reject(err)
                   }
                   if (body.errcode) {
                       reject(body.errcode)
                   }
                   resolve(body);
               })
           })
    })
}
// 只要向外暴露一个获取值的方法就可以了
module.exports = getWbInfo

